package com.feng.gameproj;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.view.View;

public class ShapeDrawableView extends View implements Runnable 
{
	private ShapeDrawable shape = null;
	private Paint paint = null;

	public ShapeDrawableView(Context context) 
	{
		super(context);
		
		this.shape = new ShapeDrawable (new RectShape ());
		this.paint = this.shape.getPaint ();
	}
	
	@Override
	protected void onDraw(Canvas canvas) 
	{
		super.onDraw(canvas);
		
		this.paint.setColor(Color.RED);
		Rect bounds = new Rect (5, 250, 55, 280);
		// 设置图像显示区域
		this.shape.setBounds(bounds);
		// 绘制图像
		this.shape.draw(canvas);
		
	}

	@Override
	public void run() 
	{
		while (!Thread.currentThread().isInterrupted())
		{
			try 
			{
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Thread.currentThread().interrupt();
			}
			postInvalidate ();
		}
	}

}
